package com.aaa.controller;

import com.aaa.entity.Log;
import com.aaa.entity.MyReturn;
import com.aaa.service.LogService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("log")
public class LogController{
    @Autowired
    private LogService logService;

    MyReturn myReturn=new MyReturn();

    BaseController baseController=new BaseController();

    @RequestMapping("toShowLog.do")
    public String toShowUserPage(){
        return "showLog";
    }
    /**
    * @Author: WTH
    * @Description: 查询,分页，计算总条数
    * @Date:2022-07-04 19:57
    * @Params:
    */
    @ResponseBody
    @RequestMapping("selectLog.do")
    public MyReturn selectLog(Log log){
        Page<Log> logs = logService.selectLog(log);
        myReturn.setData(logs.getResult());
        baseController.getSuccessReturn(myReturn);
        myReturn.setCount(logs.getTotal());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 新增
    * @Date:2022-07-06 17:18
    * @Params:
    */
    @ResponseBody
    @RequestMapping("addLog.do")
    public MyReturn addLog(Log log){
        int i = logService.addLog(log);
        if(i>0){
            baseController.getSuccessResult(myReturn);
        }else{
            baseController.getFailResult(myReturn);
        }
        return myReturn;
    }
}
